{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "AugLy_text.ipynb",
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "ABLd8on9lFwK"
      },
      "source": [
        "# Note: restart runtime after this import before running the augmentations\n",
        "!pip install -U augly[text]\n",
        "!sudo apt-get install python3-magic"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LJeIPC67lJet"
      },
      "source": [
        "import augly.text as textaugs\n",
        "\n",
        "# Define input text\n",
        "input_text = \"Hello, world! How are you today?\"\n",
        "input_text"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LdGl0JxjlRXR"
      },
      "source": [
        "# Now we can apply various augmentations!\n",
        "print(textaugs.simulate_typos(input_text))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-PklmlHolR4j"
      },
      "source": [
        "\"\"\"\n",
        "You can optionally pass in a metadata list, to which metadata about the\n",
        "augmentation will be appended including kwargs and intensity (defined based on\n",
        "the kwargs for each augmentation).\n",
        "\"\"\"\n",
        "meta = []\n",
        "print(\n",
        "    textaugs.replace_fun_fonts(\n",
        "        input_text, vary_fonts=True, granularity=\"word\", metadata=meta\n",
        "    )\n",
        ")\n",
        "meta"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_ab92YUjyM6y"
      },
      "source": [
        "# For all the augmentations, we have class-based definitions as well as\n",
        "# functional\n",
        "meta = []\n",
        "aug = textaugs.ReplaceSimilarUnicodeChars(aug_word_p=0.6)\n",
        "print(aug(input_text, metadata=meta))\n",
        "meta"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "9-IMYGRyzNen",
        "outputId": "eb1836f7-2e0c-4339-93df-3460529e07fd",
        "colab": {
          "base_uri": "https://localhost:8080/"
        }
      },
      "source": [
        "# You can evaluate the fairness of your model by swapping gender in text\n",
        "# inputs & evaluating the performance!\n",
        "gendered_text = \"She has two brothers, but she always wanted a sister\"\n",
        "aug = textaugs.SwapGenderedWords(aug_word_p=1.0)\n",
        "print(aug(gendered_text))"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "P_pXLW_l7euY"
      },
      "source": [
        "aug = textaugs.Contractions(aug_p=1.0)\n",
        "print(aug(input_text))"
      ],
      "execution_count": null,
      "outputs": []
    }
  ]
}